package kr.saeildamil.androidStudy_second.fragment.common;

import kr.saeildamil.androidStudy_second.R;
import android.app.Activity;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class WordListFragment extends ListFragment {
	/*String[] words;
	String[] details;*/
	OnWordChangedListener mHost;

	public interface OnWordChangedListener {
		public void onWordChanged(int index);
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		try {
			mHost = (OnWordChangedListener) activity;
		} catch (ClassCastException e) {
			//activity가 반드시 OnWordChangerdListener를 구현해야됨
			throw new ClassCastException(
					"Activity must implement OnWordChangerd");
		}
	}

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	/*	words = getResources().getStringArray(R.array.word);
		details = getResources().getStringArray(R.array.desc);*/
	}

	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
				getActivity(), R.array.word,
				android.R.layout.simple_list_item_1);

		setListAdapter(adapter);
		getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
		
		/*words = getResources().getStringArray(R.array.word);
		details = getResources().getStringArray(R.array.desc);*/
	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		mHost.onWordChanged(position);
		/*words = getResources().getStringArray(R.array.word);
		String message = words[position] + ":" + details[position];
		Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();*/
	}
}
